<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>冒泡排序</title>
</head>
<body>

<script>
    var arr=[5,3,2,1];
   /*     if(arr[0]>arr[0+1]){
            var temp=arr[0];
            arr[0]=arr[0+1];
            arr[0+1]=temp;
        }
        console.log(arr);
        //3 5 2  1
      if(arr[1]>arr[1+1]){
            var temp=arr[1];
            arr[1]=arr[1+1];
            arr[1+1]=temp;
        }
        console.log(arr);
        // 3 2 5 1
        if(arr[2]>arr[2+1]){
            var temp=arr[2];
            arr[2]=arr[2+1];
            arr[2+1]=temp;
        }
        console.log(arr);
        // 3 2 15

        if(arr[0]>arr[0+1]){
            var temp=arr[0];
            arr[0]=arr[0+1];
            arr[0+1]=temp;
        }
    console.log(arr);
    //2 3 15
    if(arr[1]>arr[1+1]){
        var temp=arr[1];
        arr[1]=arr[1+1];
        arr[1+1]=temp;
    }

    console.log(arr);
    //2 1 3 5


        if(arr[0]>arr[0+1]) {
            var temp = arr[0];
            arr[0] = arr[0 + 1];
            arr[0 + 1] = temp;


        }
            console.log(arr);
*/

    for(var i=0;i<arr.length-1; i++){
        for(var j = 0 ;j < arr.length - i - 1; j++){
            if(arr[j]>arr[j+1]){
                var temp=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=temp;
            }
        }
    }
    console.log(arr);

</script>

</body>
</html>